#include <cstdio>

using namespace std; 

#define N 2010

int ra[N], rb[N]; 
int r[N]; 

int sys; 

void add(int *a, int *b, int *res)
{
    int out; 

	res[0] = 0; 
    for (int i=0; i<N-2; i++) {
        int t = res[i] + a[i] + b[i]; 
        res[i] = t % sys; 
        res[i+1] = t / sys; 
    }
}

void show(int *res)
{
    int out = 0; 
    for (int i=N-1; i>=0; i--) {
        if (out || res[i]!=0 || i==0) {
        	if (res[i]>=0 && res[i]<=9) 
            	printf("%d", res[i]); 
            else
            	printf("%c", res[i]-10+'A'); 
            out = 1; 
        }
    }
    printf("\n"); 
}

int get_n(int *r)
{
	static char s[N]; 
	int i, p, ret; 
	
	fgets(s, sizeof(s), stdin); 
	for(p=0; p<N; p++) {
		if ((s[p]<'0' || s[p]>'9') && (s[p]<'A' || s[p]>'Z'))
			break; 
	}
	p--; 
	ret = p; 
	for (i=0; p>=0; i++, p--) {
		r[i] = (s[p]>='0' && s[p]<='9') ? s[p]-'0' : s[p]-'A'+10; 
	}
	return ret; 
}

int main()
{
	scanf("%d\n", &sys); 
	get_n(ra); 
	get_n(rb); 
	add(ra, rb, r); 
	show(r); 
	return 0; 
}


